<template>
	<view :class="uiStyle == 1 ? '' : 'uiStyle'">
		<!-- 预约包月 -->
		<topBar text="预约" :needBack="true"></topBar>
		<view class="head-block" v-if="weixin == 2">
			<!-- <image src="../../static/assets/img/my/jifenBG.png" class="bgimg" mode="widthFix"></image> -->
			<view class="nav-title" :style="'top:10px'"></view>
		</view>
		<!-- 返回 -->
		<view class="icon" v-if="weixin == 2" @tap="goMy" :style="'top:10px'">
			<van-icon name="arrow-left" color="#fff" size="45rpx" />
		</view>
		<view style="position: relative;" :style="weixin == 2 ? 'top:60rpx' : '0'">
			
			<view class="select">已选择 <text class="surplus" v-if="realFreeNum">剩余车位：{{realFreeNum}}</text></view>
			
			<view class="card-top" v-if="setMenuFlag" @tap="onSelectMenu" :data-data="item"
				v-for="(item, index) in setMenu" :key="index">
				<image src="../../static/assets/img/greencard.png" class="bg-img"></image>

				<view class="card-top-contain">
					<view :class="'bg-discount ' + (item.id == 2 ? 'bg-dis-green' : 'bg-dis-gray')"
						v-if="item.isShowDiscount">（您为首次包月，可享专属折扣）</view>
					<view :class="'bg-selected ' + (item.id == '2' ? 'bg-left-green' : 'bg-left-green')">
						{{ spaceNo ? '固定车位' : item.productName }}
					</view>
					<view class="park-title" v-if="!spaceNo">
						<image src="../../static/assets/img/pos.png" class="tagimg" mode="widthFix"
							style="width: 24rpx">
						</image>
						{{ datas.parkingName || '暂未获取到车场名称' }}
					</view>
					<view class="park-title" v-else>
						<text v-if="spaceNo">车 位 号：{{ spaceNo }}</text>
					</view>

					<view class="park-title2" v-if="!spaceNo">
						{{ datas.address }}
					</view>
					<view class="park-title2" v-else>
						共享日期：
						<text style="color: #000">{{ manage.validStartTime }}~{{ manage.validEndTime }}</text>
					</view>
					<view class="park-title2" v-if="spaceNo">
						价 格：
						<text style="color: #000">{{ manage.unitPrice / 100 }}元/月</text>
						<!-- <view>（国标/特斯拉专用）</view> -->
					</view>
					<text class="park-title2" v-if="manage.haveCharge">（本车位可提供充电服务，费用双方自行商议）</text>
					
					<view class="price" v-if="!spaceNo">
						<view v-if="!item.isShowDiscount" class="price-rt">
							<view class="price-strong">
								{{ item.price }}
								<text style="font-size: 20rpx; color: #757575">元/月</text>
							</view>
							<view class="menu-box-item menu-red" v-if="type == 1">包月</view>
							<view class="menu-box-item menu-gray" v-if="type == 2">夜间月卡</view>
						</view>
						<view v-else class="pirce-discount">
							<view :class="'price-dis-rt ' + (item.id == 2 ? 'price-green' : 'price-gray')">
								<view class="price-dis-strong">￥{{ item.discountData.nowPrice / 100 }}</view>
								<view style="font-size: 20rpx">元</view>
							</view>
							<view class="price-del">原价￥{{ item.price }}元</view>
						</view>
					</view>
					<view :class="'parkrecommend ' + (focus == 1 ? 'like1' : 'nolike1') + ' '" :data-item="datas"
						:data-index="index" :data-isFocus="focus" :data-id="spaceNo ? spaceNoId : datas.parkingCode"
						@tap.stop.prevent="likeThisPark">
						{{ focus == 1 ? '已关注' : '+关注' }}
					</view>
					<view class="concant" v-if="spaceNo" :style="'bottom:' + (spaceNo ? '0' : '-60rpx')"
						:data-item="manage" :data-index="index" :data-id="item.parkingCode" @tap="gotoMessage"
						:data-url="'../socks/socks?manageId=' + manage.id + '&recipientUserId=' + manage.identityId + '&otherName=' + manage.manageName">
						<image src="../../static/assets/img/message.png" class="img-msg"></image>
						留言咨询
					</view>

					<!-- <view class="line"></view> -->
					<view class="top-free" v-if="!spaceNo">
						<text
							class="bottomTip">开放时间段：<text class="bold">{{ type == 1 ? '全天' : item.reservationTimeContent || '--' }}</text></text>
						<!-- <text class="bottomTip">{{ item.productDesc || '--' }}</text> -->
						
						<text class="bottomTip" v-if="lltParkingInfoType == 2">
							<text
								:class="'restNum ' + (item.rest ? 'price-green' : 'price-gray')">月卡剩余：{{ restNum }}张</text>
						</text>
					</view>
					<view v-else>
						<van-rate readonly v-model="evaluate" color="#ffd21e" void-icon="star" void-color="#eee" />
					</view>
					<view class="flex_b">
						<view class="statu" style="display: flex; padding: 0 30rpx; min-height: 30rpx">
							<view class="statuView" v-if="manage.haveCharge ? manage.haveCharge : datas.haveCharge">
								<image class="img-tag" mode="widthFix" src="../../static/assets/img/elc.png" />
								有充电桩
							</view>
							<view class="statuView" v-if="manage.spaceType ? manage.spaceType == 2 : datas.spaceType == 2">
								<image class="img-tag" mode="widthFix" src="../../static/assets/img/under.png" />
								地下
							</view>
							<view class="statuView" v-if="manage.spaceType ? manage.spaceType == 1 : datas.spaceType == 1">
								<image class="img-tag" mode="widthFix" src="../../static/assets/img/ground.png" />
								地面
							</view>
							<view class="statuView" v-if="manage.spaceType ? manage.spaceType == 3 : datas.spaceType == 3">
								<image class="img-tag" mode="widthFix" src="../../static/assets/img/3dpark.png" />
								立体车库
							</view>
						</view>
						<view class="" style="display: inline-block" :data-id="datas.contactPhone"
							@tap="handlePhoneWy">
							<image style="width: 30rpx; position: relative; top: 8rpx"
								src="../../static/assets/img/telphone.png" mode="widthFix" class="tagimg"></image>
							<!-- <text class="">{{ datas.contactPhone || '暂无联系方式' }}</text> -->
							<text class="car_phone">联系车场</text>
						</view>
					</view>
					
				</view>
			</view>
			<view class="split-line"></view>

			<view class="card-middle">
				<!-- <view class="park-title">请选择：</view> -->
				<view class="cell-btm">
					<van-cell title="月卡启用时间" is-link @click="showStartDateFun">
						<span :class="parkTime != '请选择' ? 'infoText' : ''" style="font-size: 26rpx"
							v-if="lltParkingInfoType != 2">{{ parkTime }}</span>
						<span :class="parkTime != '请选择' ? 'infoText' : ''" style="font-size: 26rpx"
							v-else>审核通过即启用(每周二、周五审核)</span>
					</van-cell>
					<van-cell title="选择包月周期" is-link @click="showStartDate2Fun" style="font-size: 26rpx">
						<span style="font-size: 26rpx" :class="monthTime != '请选择' ? 'infoText' : ''"
							v-if="lltParkingInfoType == 2 && monthTime == '12个月(8折优惠)'">
							12个月
							<image class="price8" src="../../static/assets/img/8price.png"></image>
						</span>
						<span style="font-size: 26rpx" :class="monthTime != '请选择' ? 'infoText' : ''"
							v-if="monthTime != '12个月(8折优惠)'">{{ monthTime }}</span>
					</van-cell>
					<van-cell title="您的车牌号" is-link @click="showCarFun">
						<span :class="carNo != '请选择' ? 'infoText' : ''">{{ carNo }}</span>
					</van-cell>
				</view>
				<view class="uploadImg" v-if="lltParkingInfoType == 2" style="margin: 10rpx 0">
					<text style="color: red">*</text>
					车牌号需认证后方可办理  <text style="color: #00bcab;" @click.stop="golicense" >去认证</text>
				</view>
				<van-cell title="车辆类型" v-if="lltParkingInfoType == 2" style="font-size: 26rpx">
					<radio-group @change="onChange2" class="myRadioGroup">
						<label class="radio">
							<radio color="#00BCAB" value="0" :checked="carType === '0'" />
							个人车辆
						</label>
						<label class="radio">
							<radio color="#00BCAB" value="1" :checked="carType === '1'" />
							单位车辆
						</label>
					</radio-group>
				</van-cell>
				<view class="tips-box" v-if="spaceNo != ''">
					<view class="tip-title">
						<image src="../../static/assets/img/usetip.png"></image>
						使用须知:
					</view>
					<view class="tip-content">1、为保证车位周转，最长可提前5日预约。您可以提前关注车位。</view>
					<view class="tip-content">2、为保证正常入场，请提前联系业主确认订单履约。如有争议，请在包月生效日2日内及时反馈。</view>
				</view>
				<view class="uploadImg" v-if="lltParkingInfoType == 2" style="margin: 10rpx 0">
					<text style="color: red">*</text>
					单位车辆办理包月需提供单位授权委托书
				</view>
				<!-- <view class="uploadImg" v-if="lltParkingInfoType == 2 && carType == '1'"> -->
				<view class="uploadImg" v-if="lltParkingInfoType == 2 && carType == '1'"
					style="width: 183rpx;text-align: center;">
					<view class="upload-box" v-if="fileList.length == 0" @click="uplodaImg">
						<image mode="widthFix" style="width: 150rpx" src="../../static/assets/img/img-up.png"></image>
					</view>
					<view class="upload-box" v-else @click="uplodaImg">
						<image mode="widthFix" style="width: 150rpx" :src="fileList[0].url"></image>
					</view>
					<view class="btnTip" v-if="fileList.length == 0">点击上传</view>
					<view class="btnTip" v-if="fileList.length > 0">重新上传</view>
				</view>
			</view>
			
			<view class="tips-box" v-if="datas.parkingAttribute==4">
				<view class="tip-title">使用须知：</view>
				<view class="tip-content">1、车牌号需认证后方可办理。<text style="color:#00bcab" @tap="golicenseManage()">去认证 ></text></view>
				<!-- <view>2、预约即为您预留车位，离场时扫码缴费。</view> -->
				<view class="tip-content">2、请在车位共享开放时段内停车，超时离场需根据时长缴纳超时占用费，超时达到3次后将列入黑名单影响后续正常使用。</view>
			</view>
			
			<view class="btn" @tap="submit">预约车位</view>
			
			<view class="rule">
				<view style="width: 20px;height: 20px;">
					<van-checkbox v-model="checked" checked-color="#00BCAB"></van-checkbox>
				</view>
				<view v-if="lltParkingInfoType == 2" class="rule-konw">
					我已经阅读并同意
					<text @tap="showRule2" style="color: #00bcab">《杭州高新物业管理有限公司停车场停车租赁协议》</text>
					、
					<text @tap="showRule" style="color: #00bcab">《停车服务协议》</text>
				</view>
				<text v-else @tap="showRule" class="rule-konw">
					我已经阅读并同意
					<text style="color: #00bcab">《停车服务协议》</text>
				</text>
			</view>
		</view>
		<view>
			<van-popup round v-model="showRulePop" @close="closeRule">
				<view class="rules">
					<view class="rule-title">停车服务协议</view>
					<!-- <view class="rule-content">
        {{platformRules}}
      </view> -->
					<view class="rule-content">
						<rich-text :nodes="platformRules"></rich-text>
					</view>
					<view class="rule-line"></view>
					<view class="rule-know" @tap="closeRule">我知道了</view>
				</view>
			</van-popup>
			<van-popup round v-model="showRulePop2" @close="closeRule2" style="z-index: 10;">
				<view class="rules rules2">
					<!-- <view class="rule-title">杭州高新物业管理有限公司停车场停车租赁协议</view> -->
					<view class="rule-content">
						<!-- <rich-text nodes="{{platformRules2}}"></rich-text> -->
						<image :data-data="item.url" :src="item.url" style="width: 100%" mode="widthFix"
							v-for="(item, index) in signedImg ? signedImg : signAgreeImg" :key="index"></image>
					</view>

					<view class="rule-line"></view>
					<view :class="'rule-know2 ' + (!signAgreeInfo.needUserSign ? 'rule-know3' : '')" @tap="closeRule2">
						{{ signedImg ? '确认签名' : '取消' }}
					</view>
					<view class="rule-know2" v-if="signAgreeInfo.needUserSign" @tap="goSign">
						{{ signedImg ? '重新签名' : '签名' }}
					</view>
				</view>
			</van-popup>
		</view>
		<view>
			<!-- 车辆下拉 -->
			<van-popup v-model="showCar" position="bottom" @close="onCloseCar">
				<van-picker show-toolbar :columns="carList" @confirm="onSelectCar" @cancel="onCloseCar" />
			</van-popup>
			<!-- 开始停车 -->
			<van-popup v-model="showStartDate" @close="onCloseDatePop" position="bottom">
				<van-datetime-picker type="date" v-model="currentDate" :min-date="minDate" :max-date="maxDate"
					@confirm="SelectDate" @cancel="onCloseDatePop" />
			</van-popup>

			<!-- 高新连续包月 -->
			<van-popup v-model="showStartDate2" @close="onCloseDatePop2" position="bottom">
				<van-picker :columns="columnsData" value-key="value" show-toolbar title="包月周期"
					@confirm="onConfirmPicker" @cancel="onCloseDatePop2" />
			</van-popup>
			<van-dialog id="van-dialog" />
			<van-toast id="van-toast" />
			<van-dialog id="van-dialog2" v-model="showLink" title="该车场仅开通支付宝收款功能，请点击“复制链接”至系统浏览器打开，使用支付宝支付"
				confirm-button-text="复制链接" cancel-button-text="取消" confirm-button-color="#00BCAB"
				cancel-button-color="#AEAEAE" v-model-cancel-button="true" :message="link"
				@confirm="copyLink($event, { tagId: 'van-dialog2' })" />
			<van-dialog id="van-dialog2" v-model="isShowPayTip" title="支付提醒" confirm-button-text="去支付"
				cancel-button-text="稍后再看" confirm-button-color="#00BCAB" cancel-button-color="#AEAEAE"
				v-model-cancel-button="true" message="您有订单未支付，请尽快支付"
				@confirm="gotoPay($event, { tagId: 'van-dialog2' })" />
		</view>
		<!-- 签名 -->
		<view class="wrapper" style="z-index: 100;" v-if="showSign">
			<view class="handRight">
				<view class="handTitle">签名</view>
			</view>

			<view class="handCenter" style="z-index: 101;">
				<canvas class="handWriting" :disable-scroll="true" @touchstart="uploadScaleStart"
					@touchmove="uploadScaleMove" @touchend="uploadScaleEnd" @tap="mouseDown"
					canvas-id="handWriting"></canvas>
			</view>
			<view class="handBtn">
				<button @tap.stop.prevent="retDraw" class="delBtn">重写</button>
				<button @tap.stop.prevent="closeSign" class="backBtn">返回</button>
				<button @tap.stop.prevent="subCanvas" class="subBtn">完成</button>
			</view>
		</view>
	</view>
</template>

<script>
	// import vanCell from '@vant/weapp/cell/index';
	// import vanCellGroup from '@vant/weapp/cell-group/index';
	// import vanCheckbox from '@vant/weapp/checkbox/index';
	// import vanPicker from '@vant/weapp/picker/index';
	import config from './../../utils/config.js';
	import util from './../../utils/util.js';
	import api from './../../utils/api.js';
	import sign from './../../utils/sign.js';
	import {
		Dialog
	} from 'vant';
	// import Toast from '@vant/weapp/toast/toast';
	export default {
		components: {
			// vanCell,
			// vanCellGroup,
			// vanCheckbox,
			// vanPicker
		},
		data() {
			return {
				setMenuFlag: false,
				type: '',
				focus: 0,
				licenseUrl: '',
				weixin: uni.getStorageSync('weixin'),
				//授权书uploadFile后的链接
				picUrlList: [],

				//授权书图片
				fileList: [],

				//授权书
				carType: '0',

				//车辆类型 高新-车辆类型0个人，1单位
				spaceNo: '',

				signedInfo: {},

				//签署完的签名
				signedImg: '',

				//签署完的图片地址
				signAgreeInfo: {
					needUserSign: false
				},

				//高新pdf签名信息
				signAgreeImg: '',

				//高新pdf
				showSign: false,

				lltParkingInfoType: '',

				//lltParkingInfoType（邻里停停车场类型，0默认，1普通车场，2高新车场）
				carNo: '请选择',

				parkTime: '请选择',

				//租赁开始时间
				monthTime: '1个月',

				//高新包月时间
				monthTimeKey: 1,

				showCar: false,
				restNum: 1,
				showPark: false,
				checked: false,

				columnsData: [{
						key: 1,
						value: '1个月'
					},
					{
						key: 2,
						value: '2个月'
					},
					{
						key: 3,
						value: '3个月'
					},
					{
						key: 4,
						value: '4个月'
					},
					{
						key: 5,
						value: '5个月'
					},
					{
						key: 6,
						value: '6个月'
					},
					{
						key: 7,
						value: '7个月'
					},
					{
						key: 8,
						value: '8个月'
					},
					{
						key: 9,
						value: '9个月'
					},
					{
						key: 10,
						value: '10个月'
					},
					{
						key: 11,
						value: '11个月'
					},
					{
						key: 12,
						value: '12个月(8折优惠)'
					}
				],

				showRulePop: false,
				showRulePop2: false,
				showStartDate: false,

				datas: {
					address: '',
					haveCharge: '',
					spaceType: 0,
					parkingCode: '',
					contactPhone: ''
				},

				rules1: config.bookparkRules,
				fix: '',

				//0固定 1不固定
				carList: '',

				setMenu: [{
						id: 2,
						//2包月 --传参
						productId: 3333,
						price: 233,
						reservationTimeContent: '18：00~次日凌晨2:00',
						productDesc: '不限制进出天数',
						productName: '包整月卡'
					},
					{
						id: 3,
						//2包月 --传参
						productId: 3333,
						price: 233,
						reservationTimeContent: '18：00~次日凌晨2:00',
						productDesc: '不限制进出天数',
						productName: '夜间月卡'
					}
				],

				nomenu: ['暂不支持包月'],
				selectedmenu: false,

				//是否选择了套餐
				columnsTime: [],

				//租赁期限列表
				showRentmonth: '',

				//租赁弹窗
				minDate: new Date(new Date().getTime() + 2 * 24 * 60 * 60 * 1000),

				maxDate: '',

				//new Date(new Date().getTime() + 24 * 60 * 60 * 1000 * 90).getTime()
				currentDate: new Date(new Date().getTime() + 24 * 60 * 60 * 1000).getTime(),

				rentType: '',

				//选择的套餐号
				productId: '',

				//套餐产品id
				platformRules: config.platformRules,

				platformRules2: config.platformRules2,
				link: '',

				//支付宝支付链接,
				showLink: false,

				isShowPayTip: false,
				gotopayType: '',
				price: [],
				isAlipay: '',
				isWechat: '',
				isShowDiscount1: false,

				//是否展示包整月卡折扣信息
				isShowDiscount2: false,

				//是否展示夜间月卡折扣信息
				isNewUser: false,

				//是否是可享受优惠的新用户
				//签名参数
				canvasName: 'handWriting',

				ctx: '',
				canvasWidth: 0,
				canvasHeight: 0,
				transparent: 1,

				// 透明度
				selectColor: 'black',

				lineColor: '#1A1A1A',

				// 颜色
				lineSize: 1.5,

				// 笔记倍数
				lineMin: 0.5,

				// 最小笔画半径
				lineMax: 4,

				// 最大笔画半径
				pressure: 1,

				// 默认压力
				smoothness: 60,

				//顺滑度，用60的距离来计算速度
				currentPoint: {},

				currentLine: [],

				// 当前线条
				firstTouch: true,

				// 第一次触发
				radius: 1,

				//画圆的半径
				cutArea: {
					top: 0,
					right: 0,
					bottom: 0,
					left: 0
				},

				//裁剪区域
				bethelPoint: [],

				//保存所有线条 生成的贝塞尔点；
				lastPoint: 0,

				chirography: [],

				//笔迹
				currentChirography: {},

				//当前笔迹
				//划线轨迹 , 生成线条的实际点
				linePrack: [],

				spaceNoId: '',
				parkingCode: '',
				showStartDate2: false,
				evaluate: '',

				manage: {
					validStartTime: '',
					validEndTime: '',
					unitPrice: 0,
					haveCharge: '',
					spaceType: false,
					id: '',
					identityId: '',
					manageName: ''
				},

				rentMonth: '',
				monthSum: '',
				uiStyle: 1,
				realFreeNum:''
			};
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			this.uiStyle = uni.getStorageSync('uiStyle') || 1
			console.log(options)
			if(options.realFreeNum){
				this.setData({
					realFreeNum:options.realFreeNum
				})
			}
			
			if (options.spaceNo) {
				this.setData({
					spaceNo: options.spaceNo
				});
				this.setData({
					maxDate: new Date(new Date().getTime() + 6 * 24 * 60 * 60 * 1000)
				});
			} else {
				this.setData({
					maxDate: new Date(new Date().getTime() + 10 * 365 * 24 * 60 * 60 * 1000)
				});
			}

			if (options.focus) {
				this.setData({
					focus: options.focus
				});
			}

			if (options.spaceNoId) {
				this.setData({
					spaceNoId: options.spaceNoId
				});
			}

			if (options.type) {
				this.setData({
					type: options.type
				});
			}
			var that = this;
			let canvasName = this.canvasName;
			this.ctx = uni.createCanvasContext(canvasName);
			let date1 = util.getDate(this.minDate, 'yyyy-MM-dd');
			this.setData({
				carList: uni.getStorageSync('plateNos').split(','),
				carNo: uni.getStorageSync('plateNos').split(',')[0] || '请选择' // fix: options.fix,
				// maxDate: new Date(this.addmulMonth(date1, 3)).getTime(),
			});
			uni.showLoading({
				title: '加载中'
			});
			this.setData({
				lltParkingInfoType: options.lltParkingInfoType,
				isAlipay: options.isAlipay,
				isWechat: options.isWechat,
				parkingCode: options.param
			});

			if (this.lltParkingInfoType != 2) {
				that.setData({
					columnsData: [{
							key: 1,
							value: '1个月'
						},
						{
							key: 2,
							value: '2个月'
						},
						{
							key: 3,
							value: '3个月'
						},
						{
							key: 4,
							value: '4个月'
						},
						{
							key: 5,
							value: '5个月'
						},
						{
							key: 6,
							value: '6个月'
						},
						{
							key: 7,
							value: '7个月'
						},
						{
							key: 8,
							value: '8个月'
						},
						{
							key: 9,
							value: '9个月'
						},
						{
							key: 10,
							value: '10个月'
						},
						{
							key: 11,
							value: '11个月'
						},
						{
							key: 12,
							value: '12个月'
						}
					]
				});
			}

			if (this.lltParkingInfoType == 2) {
				//获取获取停车场用户协议
				var agreeParam = {};
				agreeParam.parkingCode = this.parkingCode;
				agreeParam.plateNo = this.carNo;
				util.request(api.getParkingUserAgreement, agreeParam, 'post')
					.then((res) => {
						//请求成功
						if (res.code == 0) {
							that.setData({
								signAgreeInfo: res.data
							});
							if (that.signAgreeInfo.testAgreementUrl) {
								//获取解密后pdf地址
								util.request(api.getEncryPath + '?path=' + that.signAgreeInfo.testAgreementUrl, '',
									'POST').then((res) => {
									var covertPar = {
										url: res,
										dpi: 300
									};
									util.request(api.convertNew, covertPar, 'POST').then((it) => {
										
										it.data.forEach(item=>{
											if(item.url.split('://')[0] == 'http'){
												item.url = item.url.replace('http','https')
											}
										})
										that.setData({
											signAgreeImg: it.data
										});
									});
								});
							}
						} else {
							that.setData({
								signAgreeInfo: {}
							});
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					})
					.catch((err) => {
						//请求失败
					});
				util.request(api.getMonthSpace + '?parkingCode=' + this.parkingCode, 'get')
					.then((res) => {
						//请求成功
						if (res.code == 0) {
							this.setData({
								restNum: res.data
							});
						} else {
							this.setData({
								restNum: 0
							});
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					})
					.catch((err) => {
						//请求失败
					});
			}
			let userParam = {
				userUnionId: uni.getStorageSync('unionId'),
				type: 1
			};
			util.request(api.isDiscountUser, userParam, 'GET')
				.then((resp) => {
					uni.hideLoading();

					if (resp.success) {
						this.setData({
							isNewUser: resp.data
						});
					}

					this.getProductList(options);
				})
				.catch((err) => {
					uni.hideLoading();
					this.getProductList(options);
				});
				
				
		},
		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {
			var query = uni.createSelectorQuery().in(this);
			query
				.select('.handCenter')
				.boundingClientRect((rect) => {
					this.setData({
						canvasWidth: rect.width,
						canvasHeight: rect.height
					});
				})
				.exec();
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {},
		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},
		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},
		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},
		/**
		 * 页面上拉触底事件的处理函数
		 */
		// onShareAppMessage: function () {
		// }
		onReachBottom: function() {},
		/**
		 * 用户点击右上角分享
		 */
		
		methods: {
			golicense(){
				uni.navigateTo({
					url:'../licenseManage/licenseManage'
				})
			},	
			goMy() {
				uni.navigateBack({
					delta: 1
				});
			},
			handlePhoneWy(e) {
				if (uni.getStorageSync('weixin') == 3 || uni.getStorageSync('weixin') == 4) {
					ZWJSBridge.phoneCall({
						"corpId": e.currentTarget.dataset.id.toString()
					}).then(res => {}).catch(err => {
						console.log(err)
					})
				} else {
					uni.makePhoneCall({
						phoneNumber: e.currentTarget.dataset.id.toString()
					}).catch((e) => {
						console.log(e);
					});
				}
			},

			//留言咨询
			gotoMessage(e) {
				console.log(e.currentTarget.dataset);
				const identityId = uni.getStorageSync('identityId');
				let recipientUserId = e.currentTarget.dataset.item.identityId;

				if (identityId == recipientUserId) {
					uni.showToast({
						title: '抱歉，这个车位为你自己的车位！',
						icon: 'none'
					});
					return;
				}

				let url = e.currentTarget.dataset.url;
				uni.navigateTo({
					url
				});
			},

			likeThisPark(event) {
				//关注车场
				let that = this;

				if (event.currentTarget.dataset.id) {
					if (that.spaceNo) {
						//关注车位
						let type = event.currentTarget.dataset.isfocus == 1 ? 2 : 1; //1关注，2取消关注

						util.request(api.manageAddOrUpdateFocus + '?unionId=' + uni.getStorageSync('unionId') +
								'&manageId=' + event.currentTarget.dataset.id + '&type=' + type, 'get')
							.then((res) => {
								if (res.success) {
									if (event.currentTarget.dataset.isfocus == 1) {
										//取消关注成功
										this.setData({
											focus: 0
										});
										uni.showToast({
											title: '取消关注成功'
										});
									} else if (event.currentTarget.dataset.isfocus == 0) {
										//添加关注成功
										this.setData({
											focus: 1
										});
										uni.showToast({
											title: '关注成功'
										});
										uni.requestSubscribeMessage({
											tmplIds: ['G-qqlo3c5ARPqg9lPCnCrSUxAEgZ8bPfrEpd0UVE-8o'],

											success(sus) {},

											fail(err) {}
										});
									}

									if (this.active == 0) {
										this.getTempList();
									} else if (this.active == 1) {
										this.getMonthList();
									}
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									});
								}
							})
							.catch((err) => {
								console.log(err);
							});
					} else {
						//关注车场
						let type = this.focus == 1 ? 2 : 1; //1关注，2取消关注

						util.request(api.addOrUpdateFocus + '?unionId=' + uni.getStorageSync('unionId') + '&parkingCode=' +
								this.parkingCode + '&type=' + type, 'get')
							.then((res) => {
								if (res.success) {
									if (event.currentTarget.dataset.isfocus == 1) {
										//取消关注成功
										this.setData({
											focus: 0
										});
										uni.showToast({
											title: '取消关注成功'
										});
									} else if (event.currentTarget.dataset.isfocus == 0) {
										//添加关注成功
										this.setData({
											focus: 1
										});
										uni.showToast({
											title: '关注成功'
										});
										uni.requestSubscribeMessage({
											tmplIds: ['G-qqlo3c5ARPqg9lPCnCrSUxAEgZ8bPfrEpd0UVE-8o'],

											success(sus) {},

											fail(err) {}
										});
									}
								} else {
									uni.showToast({
										title: res.msg,
										icon: 'none'
									});
								}
							})
							.catch((err) => {
								console.log(err);
							});
					}
				}
			},

			//保存
			subCanvas() {
				var that = this;
				uni.canvasToTempFilePath({
					canvasId: 'handWriting',
					fileType: 'png',
					quality: 1,

					//图片质量
					success(res) {
						// var base64url = uni.getFileSystemManager().readFileSync(res.tempFilePath, 'base64');
						var base64url = res.tempFilePath;
						// console.log(base64url, 'canvas生成图片地址'); //获取获取停车场用户协议

						uni.showLoading({});
						var userSign = {};
						userSign.parkingCode = that.parkingCode;
						userSign.unionId = uni.getStorageSync('unionId');
						userSign.userAgreementSign = base64url;
						userSign.plateNo = that.carNo;
						util.request(api.userSign, userSign, 'post')
							.then((result) => {
								//请求成功
								if (result.success) {
									that.setData({
										signedInfo: result.data
									});

									if (that.signedInfo.signUserAgreementUrl) {
										//获取解密后pdf地址
										util.request(api.getEncryPath + '?path=' + that.signedInfo
											.signUserAgreementUrl, '', 'POST').then((res) => {
											// that.setData({
											//   signedImg: res,
											//   showSign:false,
											// });
											var covertPar = {
												url: res,
												dpi: 300
											};
											util.request(api.convertNew, covertPar, 'POST').then((
												res) => {
												uni.hideLoading({
													success: (res) => {}
												});
												res.data.forEach(item=>{
													if(item.url.split('://')[0] == 'http'){
														item.url = item.url.replace('http','https')
													}
												})
												that.setData({
													signedImg: res.data,
													showSign: false
												});
											});
										});
									}
								} else {
			
									uni.showToast({
										title:result.msg,
										icon:'none'
									})
								}
							})
							.catch((err) => {
								uni.showToast({
									title: '抱歉，接口报错，请重试！',
									icon: 'none'
								});
							});
					}
				});
			},

			onConfirmPicker(event) {
				// if(value.value=="12个月(8折)")value.value='12个月 <image src="../../assets/img/telphone.png" class="tagimg"></image>'

				this.setData({
					monthTime: event.value,
					monthTimeKey: event.key,
					
					showStartDate2: false
				});
				
			},

			// 获取产品信息
			getProductList(e) {
				let param = {
					parkingCode: e.param,
					type: 2,
					spaceNo: this.spaceNo ? this.spaceNo : ''
				};
				util.request(api.findProductList, param, 'GET')
					.then((res) => {
						if (res.success) {
							if (res.data && res.data.manage) {
								res.data.manage.validStartTime = res.data.manage.validStartTime.split(' ')[0];
								res.data.manage.validEndTime = res.data.manage.validEndTime.split(' ')[0];
							}

							this.setData({
								datas: res.data.parkingInfo,
								price: res.data.productList,
								evaluate: res.data.evaluate,
								manage: res.data.manage ? res.data.manage : {}
							});
							if(this.datas.parkingName=='新城时代广场'){
								this.setData({
									columnsData: [{
											key: 1,
											value: '1个月'
										},
										{
											key: 2,
											value: '2个月'
										},
										{
											key: 3,
											value: '3个月(优惠)'
										},
										{
											key: 4,
											value: '4个月(优惠)'
										},
										{
											key: 5,
											value: '5个月(优惠)'
										},
										{
											key: 6,
											value: '6个月(优惠)'
										},
										{
											key: 7,
											value: '7个月(优惠)'
										},
										{
											key: 8,
											value: '8个月(优惠)'
										},
										{
											key: 9,
											value: '9个月(优惠)'
										},
										{
											key: 10,
											value: '10个月(优惠)'
										},
										{
											key: 11,
											value: '11个月(优惠)'
										},
										{
											key: 12,
											value: '12个月(优惠)'
										}
									]
								});
							}
							this.composeSetmenu();
						}
					})
					.catch((err) => {
						console.log(err);
					});
			},

			// 生成卡片套餐
			composeSetmenu() {
				let menu = this.price;
				var that = this;
				let setMenu = [];

				if (menu && menu != null && menu.length > 0) {
					menu.map((item) => {
						if (item.type == '1' && that.type == item.type) {
							let discountData = {};

							if (this.isNewUser) {
								//是新用户才去查有没有优惠活动
								if (item.discountList && item.discountList.length > 0) {
									item.discountList.map((i) => {
										if (i.type == '1') {
											discountData = i;
											this.setData({
												isShowDiscount1: true
											});
										}
									});
								}
							}

							setMenu.push({
								id: 2,
								//2包月 --传参
								productId: item.id,
								price: Number(item.unitPrice) / 100,
								reservationTimeContent: item.reservationTimeContent,
								productDesc: item.productDesc,
								productName: '不固定车位',
								discountData: discountData,
								isShowDiscount: this.isShowDiscount1
							});
						} else if (item.type == '2' && that.type == item.type) {
							let discountData = {};

							if (this.isNewUser) {
								//是新用户才去查有没有优惠活动
								if (item.discountList && item.discountList.length > 0) {
									item.discountList.map((i) => {
										if (i.type == '1') {
											discountData = i;
											this.setData({
												isShowDiscount2: true
											});
										}
									});
								}
							}

							setMenu.push({
								id: 3,
								//3 夜间包月-传参
								productId: item.id,
								price: Number(item.unitPrice) / 100,
								reservationTimeContent: item.reservationTimeContent,
								productDesc: item.productDesc,
								productName: '不固定车位',
								discountData: discountData,
								isShowDiscount: this.isShowDiscount2
							});
						}
					});
				}
				this.setData({
					setMenuFlag: true,
					setMenu: setMenu,
					rentType: setMenu[0].id || '',
					productId: setMenu[0].productId || ''
				});
			},

			onChange(event) {
				if (this.signAgreeInfo.needUserSign && !this.signedImg) {
					Toast('请先点击阅读停车租赁协议并签名');
					return;
				}

				this.setData({
					checked: event.detail
				});
			},

			onChange2(event) {
				this.setData({
					carType: event.detail.value
				});
			},

			gotoSubmit() {
				var that = this;
				uni.showLoading({
					title: '加载中'
				});
				let param = {
					unionId: uni.getStorageSync('unionId'),
					startTime: this.parkTime,
					parkingCode: this.datas.parkingCode,
					plateNo: this.carNo,
					rentedType: this.rentType,
					// "monthSum": 1,
					productId: this.productId
				};

				if (that.lltParkingInfoType == 2) {
					param.monthSum = this.monthTimeKey;

					if (this.carType == '1' && this.fileList.length == 0) {
						uni.hideLoading();
						uni.showToast({
							title:'抱歉，请先上传单位授权委托书',
							icon:'none'
						})
						return;
					} else {
						if (this.carType == '0') {
							//个人 authBookImg高新-公司车辆授权书图片，车辆类型为单位时必传
							param.applicant = this.carType; // param.authBookImg=this.data.licenseUrl;
						} else {
							//企业
							param.applicant = this.carType;
							param.authBookImg = this.licenseUrl;
						}
					}
				} else {
					param.monthSum = this.monthTimeKey;
				}

				if (this.spaceNo != '') {
					param.spaceNo = this.spaceNo;
				}

				if (that.signAgreeInfo.needUserSign) {
					param.plmSignUserAgreementId = this.signedInfo.id;
				}
				var payType = uni.getStorageSync('weixin') == 2 ? 2 : 1
				// if (this.isAlipay == 1 && this.isWechat == 0) {
				// 	param.payType = '1';
				// 	param.AUTHORIZATION = uni.getStorageSync('AUTHORIZATION');
				// 	uni.hideLoading();
				// 	this.setData({
				// 		showLink: true,
				// 		link: encodeURIComponent(JSON.stringify(param))
				// 	});
				// } else {
				param.payType = payType
				if (payType == 2) {
					util.request(api.unionPayMonthReserve, param, 'POST')
						.then((res) => {
							if (res.success) {
								//这里一定是微信支付了
								uni.hideLoading();
								if (that.lltParkingInfoType == 2) {
									var param = encodeURIComponent(res.data);
									uni.showToast({
										title: '提交成功'
									});
									uni.navigateTo({
										url: '../wechatPay/wechatPay?param=' + param  + "&from=02&lltParkingInfoType=" + that.lltParkingInfoType
									});
								} else if(that.lltParkingInfoType == 3){
									var {url,content,wxContent} = JSON.parse(res.data)
									jWeixin.miniProgram.navigateTo({url:"/pages/wxContent/wxContent?param=" + wxContent})
									// uni.navigateTo({
									// 	url: '../wechatPay/wechatPay?param=' + wxContent  + "&from=02&lltParkingInfoType=" + that.lltParkingInfoType
									// });
									// console.log(url,content)
									// window.location.href = url + '?' + content
								}else{
									var param = encodeURIComponent(res.data);
									uni.showToast({
										title: '提交成功'
									});
									uni.navigateTo({
										url: '../wechatPay/wechatPay?param=' + param  + "&from=02&lltParkingInfoType=" + that.lltParkingInfoType
									});
								}
							} else if (res.busiCode == 'waitingToPay1') {
								uni.hideLoading();
								this.setData({
									gotopayType: 1,
									isShowPayTip: true
								});
							} else if (res.busiCode == 'waitingToPay2') {
								uni.hideLoading();
								this.setData({
									gotopayType: 2,
									isShowPayTip: true
								});
							} else {
								uni.hideLoading();

								if (res.busiCode == 'waitingToCheck') {
									Dialog.alert({
										message: res.msg || '租赁失败，请重试'
									}).then(() => {
										//  console.log("即将车牌认证")
										uni.navigateTo({
											url: '/pages/licenseManage/licenseManage'
										});
									});
								} else {
									Dialog.alert({
										message: res.msg || '租赁失败，请重试'
									}).then(() => {
										// on close
									});
								}
							}
						})
						.catch((err) => {
							Toast(err || '接口出错了，请重试');
						});
				} else {
					util.request(api.monthReserve, param, 'post').then((res) => {
						if (res.code == 0) {
							const data = res.data;
							if(that.lltParkingInfoType == 3){
								var {url,content,wxContent} = JSON.parse(data)
								window.location.href = url + '?' + content
							}else{
								document.querySelector('body').innerHTML = res.data;
								document.forms[0].submit()
							}

						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none'
							});
						}
					});
				}

			},

			submit() {
				var that = this;

				if (this.carNo == '请选择') {
					uni.showToast({
						title:'请选择车辆',
						icon:'none'
					})
					return;
				}

				if (this.rentType == '') {
					uni.showToast({
						title:'请点击卡片选择套餐',
						icon:'none'
					})
					return;
				}

				if (this.parkTime == '请选择' && this.lltParkingInfoType != 2) {
					uni.showToast({
						title:'请选择月卡启用时间',
						icon:'none'
					})
					return;
				}

				if (this.checked == false) {
					uni.showToast({
						title:'请勾选同意《停车服务协议》',
						icon:'none'
					})
					return;
				}

				if (this.monthTime == '请选择') {
					uni.showToast({
						title:'请选择包月周期',
						icon:'none'
					})
					return;
				}

				if (this.lltParkingInfoType == 2) {
					//高新新逻辑:添加黑名单
					util.request(api.checkCarNum + '?parkingCode=' + this.parkingCode + '&plateNo=' + this.carNo, 'get')
						.then((res) => {
							//请求成功
							if (res.code == 0) {
								if (res.data == 0) {
									//车牌状态0：正常车牌1：黑名单
									that.gotoSubmit();
								} else if (res.data == 1) {
									uni.showToast({
										title: '当前车牌号受控，请联系车场',
										icon: 'none'
									});
								}
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
							}
						})
						.catch((err) => {
							//请求失败
						});
					return;
				}

				this.gotoSubmit();
			},

			/**跳转支付 */
			gotoPay(e, _dataset) {
				/* ---处理dataset begin--- */
				this.datasetHandle(e, _dataset);
				/* ---处理dataset end--- */
				uni.navigateTo({
					url: '../order/index?type=' + this.gotopayType
				});
			},

			findAction(e) {
				if (e) {
					let st = e.indexOf('https');
					let ed = e.indexOf('">');
					let value = e.substring(st, ed);
					return value;
				}

				return e;
			},

			/**
			 * copyLink复制链接
			 */
			copyLink(e, _dataset) {
				/* ---处理dataset begin--- */
				this.datasetHandle(e, _dataset);
				/* ---处理dataset end--- */
				uni.setClipboardData({
					data: 'https://shareparking.wasu.cn/share-parking/static/pay.html?goto=' + this.link,
					success: () => {
						this.$emit('close');
						setTimeout(() => {
							uni.navigateTo({
								url: '../order/index?type=2'
							});
						}, 13000);
					},
					fail: () => {},
					complete: () => {}
				});
			},

			//展示规则
			showRule() {
				this.setData({
					showRulePop: true
				});
			},

			showRule2() {
				if (this.carNo == '请选择') {
					Toast('抱歉，请先选择车牌号');
					return;
				}
				this.setData({
					showRulePop2: true
				});
			},

			/**
			 * 关闭规则
			 */
			closeRule() {
				this.setData({
					showRulePop: false // checked: true,
				});
			},

			closeRule2() {
				this.setData({
					showRulePop2: false // checked: true,
				});
			},

			//签名
			closeSign() {
				this.setData({
					showSign: false
				});
			},

			//签名
			goSign() {
				this.setData({
					showSign: true
				});
			},

			/**
			 * 选择停车车辆
			 */
			onSelectCar(e) {
				var that = this;
				this.setData({
					carNo: e,
					showCar: false
				});

				if (this.lltParkingInfoType == 2) {
					//获取获取停车场用户协议
					var agreeParam = {};
					agreeParam.parkingCode = this.parkingCode;
					agreeParam.plateNo = this.carNo;
					util.request(api.getParkingUserAgreement, agreeParam, 'post')
						.then((res) => {
							//请求成功
							if (res.code == 0) {
								that.setData({
									signAgreeInfo: res.data
								});

								if (that.signAgreeInfo.testAgreementUrl) {
									//获取解密后pdf地址
									util.request(api.getEncryPath + '?path=' + that.signAgreeInfo.testAgreementUrl, '',
										'POST').then((res) => {
										var covertPar = {
											url: res,
											dpi: 300
										};
										util.request(api.convertNew, covertPar, 'POST').then((res) => {
											res.data.forEach(item=>{
												if(item.url.split('://')[0] == 'http'){
													item.url = item.url.replace('http','https')
												}
											})
											that.setData({
												signAgreeImg: res.data,
												signedImg: ''
											});
										});
									});
								}
							} else {
								that.setData({
									signAgreeInfo: {}
								});
								uni.showToast({
									title: res.msg,
									icon: 'none'
								});
							}
						})
						.catch((err) => {
							//请求失败
						});
				}
			},

			showCarFun() {
				this.setData({
					showCar: true
				});
			},

			onCloseCar() {
				this.setData({
					showCar: false
				});
			},

			/**
			 * 选择套餐
			 */
			onSelectMenu(e) {
				this.setData({
					rentType: e.currentTarget.dataset.data.id,
					productId: e.currentTarget.dataset.data.productId
				});
			},

			/**
			 * 开始停车时间
			 */
			SelectDate(e) {
				this.setData({
					showStartDate: false,
					parkTime: util.getDate(e, 'yyyy-MM-dd')
				});
			},

			showStartDateFun() {
				if (this.lltParkingInfoType == 2) {
					return;
				}

				this.setData({
					showStartDate: true
				});
			},

			showStartDate2Fun() {
				this.setData({
					showStartDate2: true,
				});
				
				// this.manage.unitPrice=
			},

			onCloseDatePop2() {
				this.setData({
					showStartDate2: false
				});
			},

			onCloseDatePop() {
				this.setData({
					showStartDate: false
				});
			},

			/**
			 * 选择租赁期限
			 */
			onChangeRentMonth(e) {
				this.setData({
					rentMonth: e.detail.value.text,
					monthSum: e.detail.value.id,
					showRentmonth: false
				});
			},

			ShowRentPop() {
				this.setData({
					showRentmonth: true
				});
			},

			onCloseRentMonth() {
				this.setData({
					showRentmonth: false
				});
			},
			uplodaImg() {
				let that = this;
				uni.chooseImage({
					count: 1, // 默认最多一次选择9张图
					success: res => {
						uni.showLoading()
						uni.uploadFile({
							url: api.vueUpload,
							filePath: res.tempFilePaths[0],
							name: 'file',
							formData: {
								user: 'test'
							},
							header: {
								Authorization: uni.getStorageSync('AUTHORIZATION') //如果需要token的话要传
							},
							success: item => {
								if (item.statusCode == 200) {
									uni.showToast({
										title: '上传成功'
									})
									var data = JSON.parse(item.data);
									let pic = that.picUrlList;
									pic.push(data.data);
									that.setData({
										picUrlList: pic,
										licenseUrl: data.data
									});

									if (data.data) {
										util.request(api.getEncryPath + '?path=' + data.data, '',
											'POST').then((res) => {
											let arr = [];
											arr.push({
												url: res
											});
											that.setData({
												fileList: arr
											});
										});
									}
								}
							},
							fail: (err) => {
								uni.showToast({
									title: '上传失败，请重新上传',
									icon: 'error'
								})
							}
						})
					}
				})
			},
			// 上传委托书
			afterRead(event) {
				const {
					file
				} = event.detail; // this.setData({ fileList: event.detail.file.url });
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式

				var that = this; //坑1： this需要这么处理

				uni.uploadFile({
					url: api.vueUpload,
					filePath: file.url,
					name: 'file',
					formData: {
						user: 'test'
					},
					header: {
						Authorization: uni.getStorageSync('AUTHORIZATION') //如果需要token的话要传
					},

					success(res) {
						var data = JSON.parse(res.data);
						let pic = that.picUrlList;
						pic.push(data.data);
						that.setData({
							picUrlList: pic,
							licenseUrl: data.data
						});

						if (data.data) {
							util.request(api.getEncryPath + '?path=' + data.data, '', 'POST').then((
								res) => {
								let arr = that.fileList;
								arr.push({
									url: res
								});
								that.setData({
									fileList: arr
								});
							});
						}
					}
				});
			},

			deleteFun(e) {
				let del = e.detail.index;
				let file = this.fileList;
				let pic = this.picUrlList;
				file.splice(del, 1);
				pic.splice(del, 1);
				this.setData({
					fileList: file,
					picUrlList: pic,
					licenseUrl: ''
				});
			},

			/**获取n个月后日期 */
			addmulMonth(date, num) {
				var newDate = new Date(date);
				var year = newDate.getFullYear();
				var month = newDate.getMonth() + num; //获取当前月份的日期

				if (month > 11) {
					for (var i = 0, j = Math.floor(month / 12); i < j; i++) {
						year++;
						month -= 12;
					}
				}

				month = parseInt(month + 1);

				if (month < 10) {
					month = '0' + month;
				}

				var date2 = new Date(year, month, 0); //新的年月

				var day1 = newDate.getDate();
				var day2 = date2.getDate();

				if (day1 > day2) {
					//防止+6月后没有31天
					day1 = day2;
				}

				return year + '-' + month + '-' + day1 + '';
			},

			/**
			 * 动态生成租赁期限
			 */
			composeColumn() {
				let arr = [];

				for (let i = 1; i <= this.datas.sumDuraTion; i++) {
					arr.push({
						text: i + '个月',
						id: i
					});
				}

				this.setData({
					columnsTime: arr
				});
			},

			// 笔迹开始
			uploadScaleStart(e) {
				if (e.type != 'touchstart') return false;
				let ctx = this.ctx;
				ctx.setFillStyle(this.lineColor); // 初始线条设置颜色

				ctx.setGlobalAlpha(this.transparent); // 设置半透明

				let currentPoint = {
					x: e.touches[0].x,
					y: e.touches[0].y
				};
				let currentLine = this.currentLine;
				currentLine.unshift({
					time: new Date().getTime(),
					dis: 0,
					x: currentPoint.x,
					y: currentPoint.y
				});
				this.setData({
					currentPoint // currentLine
				});

				if (this.firstTouch) {
					this.setData({
						cutArea: {
							top: currentPoint.y,
							right: currentPoint.x,
							bottom: currentPoint.y,
							left: currentPoint.x
						},
						firstTouch: false
					});
				}

				this.pointToLine(currentLine);
			}, // 笔迹移动

			uploadScaleMove(e) {
				if (e.type != 'touchmove') return false;

				if (e.cancelable) {
					// 判断默认行为是否已经被禁用
					if (!e.defaultPrevented) {
						e.preventDefault();
					}
				}

				let point = {
					x: e.touches[0].x,
					y: e.touches[0].y
				}; //测试裁剪

				if (point.y < this.cutArea.top) {
					this.cutArea.top = point.y;
				}

				if (point.y < 0) this.cutArea.top = 0;

				if (point.x > this.cutArea.right) {
					this.cutArea.right = point.x;
				}

				if (this.canvasWidth - point.x <= 0) {
					this.cutArea.right = this.canvasWidth;
				}

				if (point.y > this.cutArea.bottom) {
					this.cutArea.bottom = point.y;
				}

				if (this.canvasHeight - point.y <= 0) {
					this.cutArea.bottom = this.canvasHeight;
				}

				if (point.x < this.cutArea.left) {
					this.cutArea.left = point.x;
				}

				if (point.x < 0) this.cutArea.left = 0;
				this.setData({
					lastPoint: this.currentPoint,
					currentPoint: point
				});
				let currentLine = this.currentLine;
				currentLine.unshift({
					time: new Date().getTime(),
					dis: this.distance(this.currentPoint, this.lastPoint),
					x: point.x,
					y: point.y
				}); // this.setData({
				//   currentLine
				// })

				this.pointToLine(currentLine);
			}, // 笔迹结束

			uploadScaleEnd(e) {
				if (e.type != 'touchend') return 0;
				let point = {
					x: e.changedTouches[0].x,
					y: e.changedTouches[0].y
				};
				this.setData({
					lastPoint: this.currentPoint,
					currentPoint: point
				});
				let currentLine = this.currentLine;
				currentLine.unshift({
					time: new Date().getTime(),
					dis: this.distance(this.currentPoint, this.lastPoint),
					x: point.x,
					y: point.y
				}); // this.setData({
				//   currentLine
				// })

				if (currentLine.length > 2) {
					var info = (currentLine[0].time - currentLine[currentLine.length - 1].time) / currentLine
					.length; //$("#info").text(info.toFixed(2));
				} //一笔结束，保存笔迹的坐标点，清空，当前笔迹
				//增加判断是否在手写区域；

				this.pointToLine(currentLine);
				var currentChirography = {
					lineSize: this.lineSize,
					lineColor: this.lineColor
				};
				var chirography = this.chirography;
				chirography.unshift(currentChirography);
				this.setData({
					chirography
				});
				var linePrack = this.linePrack;
				linePrack.unshift(this.currentLine);
				this.setData({
					linePrack,
					currentLine: []
				});
			},

			retDraw() {
				this.ctx.clearRect(0, 0, 700, 730);
				this.ctx.draw();
			}, //画两点之间的线条；参数为:line，会绘制最近的开始的两个点；

			pointToLine(line) {
				this.calcBethelLine(line);
				return;
			}, //计算插值的方式；

			calcBethelLine(line) {
				if (line.length <= 1) {
					line[0].r = this.radius;
					return;
				}

				let x0,
					x1,
					x2,
					y0,
					y1,
					y2,
					r0,
					r1,
					r2,
					len,
					lastRadius,
					dis = 0,
					time = 0,
					curveValue = 0.5;

				if (line.length <= 2) {
					x0 = line[1].x;
					y0 = line[1].y;
					x2 = line[1].x + (line[0].x - line[1].x) * curveValue;
					y2 = line[1].y + (line[0].y - line[1].y) * curveValue; //x2 = line[1].x;
					//y2 = line[1].y;

					x1 = x0 + (x2 - x0) * curveValue;
					y1 = y0 + (y2 - y0) * curveValue;
				} else {
					x0 = line[2].x + (line[1].x - line[2].x) * curveValue;
					y0 = line[2].y + (line[1].y - line[2].y) * curveValue;
					x1 = line[1].x;
					y1 = line[1].y;
					x2 = x1 + (line[0].x - x1) * curveValue;
					y2 = y1 + (line[0].y - y1) * curveValue;
				} //从计算公式看，三个点分别是(x0,y0),(x1,y1),(x2,y2) ；(x1,y1)这个是控制点，控制点不会落在曲线上；实际上，这个点还会手写获取的实际点，却落在曲线上

				len = this.distance({
					x: x2,
					y: y2
				}, {
					x: x0,
					y: y0
				});
				lastRadius = this.radius;

				for (let n = 0; n < line.length - 1; n++) {
					dis += line[n].dis;
					time += line[n].time - line[n + 1].time;
					if (dis > this.smoothness) break;
				}

				this.setData({
					radius: Math.min((time / len) * this.pressure + this.lineMin, this.lineMax) * this.lineSize
				});
				line[0].r = this.radius; //计算笔迹半径；

				if (line.length <= 2) {
					r0 = (lastRadius + this.radius) / 2;
					r1 = r0;
					r2 = r1; //return;
				} else {
					r0 = (line[2].r + line[1].r) / 2;
					r1 = line[1].r;
					r2 = (line[1].r + line[0].r) / 2;
				}

				let n = 5;
				let point = [];

				for (let i = 0; i < n; i++) {
					let t = i / (n - 1);
					let x = (1 - t) * (1 - t) * x0 + 2 * t * (1 - t) * x1 + t * t * x2;
					let y = (1 - t) * (1 - t) * y0 + 2 * t * (1 - t) * y1 + t * t * y2;
					let r = lastRadius + ((this.radius - lastRadius) / n) * i;
					point.push({
						x: x,
						y: y,
						r: r
					});

					if (point.length == 3) {
						let a = this.ctaCalc(point[0].x, point[0].y, point[0].r, point[1].x, point[1].y, point[1].r, point[
							2].x, point[2].y, point[2].r);
						a[0].color = this.lineColor; // let bethelPoint = this.data.bethelPoint;
						// console.log(a)
						// console.log(this.data.bethelPoint)
						// bethelPoint = bethelPoint.push(a);

						this.bethelDraw(a, 1);
						point = [{
							x: x,
							y: y,
							r: r
						}];
					}
				}

				this.setData({
					currentLine: line
				});
			}, //求两点之间距离

			distance(a, b) {
				let x = b.x - a.x;
				let y = b.y - a.y;
				return Math.sqrt(x * x + y * y);
			},

			ctaCalc(x0, y0, r0, x1, y1, r1, x2, y2, r2) {
				let a = [],
					vx01,
					vy01,
					norm,
					n_x0,
					n_y0,
					vx21,
					vy21,
					n_x2,
					n_y2;
				vx01 = x1 - x0;
				vy01 = y1 - y0;
				norm = Math.sqrt(vx01 * vx01 + vy01 * vy01 + 0.0001) * 2;
				vx01 = (vx01 / norm) * r0;
				vy01 = (vy01 / norm) * r0;
				n_x0 = vy01;
				n_y0 = -vx01;
				vx21 = x1 - x2;
				vy21 = y1 - y2;
				norm = Math.sqrt(vx21 * vx21 + vy21 * vy21 + 0.0001) * 2;
				vx21 = (vx21 / norm) * r2;
				vy21 = (vy21 / norm) * r2;
				n_x2 = -vy21;
				n_y2 = vx21;
				a.push({
					mx: x0 + n_x0,
					my: y0 + n_y0,
					color: '#1A1A1A'
				});
				a.push({
					c1x: x1 + n_x0,
					c1y: y1 + n_y0,
					c2x: x1 + n_x2,
					c2y: y1 + n_y2,
					ex: x2 + n_x2,
					ey: y2 + n_y2
				});
				a.push({
					c1x: x2 + n_x2 - vx21,
					c1y: y2 + n_y2 - vy21,
					c2x: x2 - n_x2 - vx21,
					c2y: y2 - n_y2 - vy21,
					ex: x2 - n_x2,
					ey: y2 - n_y2
				});
				a.push({
					c1x: x1 - n_x2,
					c1y: y1 - n_y2,
					c2x: x1 - n_x0,
					c2y: y1 - n_y0,
					ex: x0 - n_x0,
					ey: y0 - n_y0
				});
				a.push({
					c1x: x0 - n_x0 - vx01,
					c1y: y0 - n_y0 - vy01,
					c2x: x0 + n_x0 - vx01,
					c2y: y0 + n_y0 - vy01,
					ex: x0 + n_x0,
					ey: y0 + n_y0
				});
				a[0].mx = a[0].mx.toFixed(1);
				a[0].mx = parseFloat(a[0].mx);
				a[0].my = a[0].my.toFixed(1);
				a[0].my = parseFloat(a[0].my);

				for (let i = 1; i < a.length; i++) {
					a[i].c1x = a[i].c1x.toFixed(1);
					a[i].c1x = parseFloat(a[i].c1x);
					a[i].c1y = a[i].c1y.toFixed(1);
					a[i].c1y = parseFloat(a[i].c1y);
					a[i].c2x = a[i].c2x.toFixed(1);
					a[i].c2x = parseFloat(a[i].c2x);
					a[i].c2y = a[i].c2y.toFixed(1);
					a[i].c2y = parseFloat(a[i].c2y);
					a[i].ex = a[i].ex.toFixed(1);
					a[i].ex = parseFloat(a[i].ex);
					a[i].ey = a[i].ey.toFixed(1);
					a[i].ey = parseFloat(a[i].ey);
				}

				return a;
			},

			bethelDraw(point, is_fill, color) {
				let ctx = this.ctx;
				ctx.beginPath();
				ctx.moveTo(point[0].mx, point[0].my);

				if (undefined != color) {
					ctx.setFillStyle(color);
					ctx.setStrokeStyle(color);
				} else {
					ctx.setFillStyle(point[0].color);
					ctx.setStrokeStyle(point[0].color);
				}

				for (let i = 1; i < point.length; i++) {
					ctx.bezierCurveTo(point[i].c1x, point[i].c1y, point[i].c2x, point[i].c2y, point[i].ex, point[i].ey);
				}

				ctx.stroke();

				if (undefined != is_fill) {
					ctx.fill(); //填充图形 ( 后绘制的图形会覆盖前面的图形, 绘制时注意先后顺序 )
				}

				ctx.draw(true);
			},

			selectColorEvent(event) {
				var color = event.currentTarget.dataset.colorValue;
				var colorSelected = event.currentTarget.dataset.color;
				this.setData({
					selectColor: colorSelected,
					lineColor: color
				});
			}, //设置canvas背景色  不设置  导出的canvas的背景为透明
			//@params：字符串  color

			setCanvasBg(color) {
				/* 将canvas背景设置为 白底，不设置  导出的canvas的背景为透明 */
				//rect() 参数说明  矩形路径左上角的横坐标，左上角的纵坐标, 矩形路径的宽度, 矩形路径的高度
				//这里是 canvasHeight - 4 是因为下边盖住边框了，所以手动减了写

				this.ctx.rect(0, 0, this.canvasWidth, this.canvasHeight - 4); // ctx.setFillStyle('red')

				this.ctx.setFillStyle(color);
				this.ctx.fill(); //设置填充

				this.ctx.draw(); //开画
			},
			golicenseManage(){
				uni.navigateTo({
					url:'../licenseManage/licenseManage'
				})
			}
		}
	};
</script>
<style>
	@import './newMonthpark.css';
</style>
